﻿#include "log.h"

Log* Log::m_instance = nullptr;
mutex resource_mutex_log;
Log::Log()
{
	log4cplus::initialize();

	PropertyConfigurator::doConfigure(LOG4CPLUS_TEXT(MY_LOG_FILE_PATH));
	logger = Logger::getRoot();
}

Log* Log::GetInstance()
{
	if (nullptr == m_instance)			//双重锁定（双重检查）  
	{
		std::unique_lock<std::mutex> mymutex(resource_mutex_log);
		if (nullptr == m_instance)
		{
			m_instance = new Log();
			static CGar_Log c1;
		}
	}
	return m_instance;
}

class CGar_Log
{
	friend Log;
public:
	~CGar_Log()
	{
		if (Log::m_instance)
		{
			//LOG_INFO("exit!!!");
			log4cplus::Logger::shutdown();
			log4cplus::deinitialize();
			delete Log::m_instance;
			Log::m_instance = nullptr;
		}
	}
};